import Vue from "vue";
// import iView from 'view-design'
import VueI18n from "vue-i18n";
import EN from "./EN";
import CN from "./CN";
import FR from "./FR";
//引入element-ui 语言包
import elementEN from "element-ui/lib/locale/lang/en";
import elementZH from "element-ui/lib/locale/lang/zh-CN";
import elementFR from "element-ui/lib/locale/lang/fr";

// 引入iview的中英文翻译
// import iviewZH from 'view-design/dist/locale/CN'
// import iviewEN from 'view-design/dist/locale/EN'

Vue.use(VueI18n);
Vue.locale = () => {};

var locale = localStorage.getItem("lang") ? localStorage.getItem("lang") : "EN";
export const i18n = new VueI18n({
  locale: locale,
  fallbackLocale: "CN",
  messages: {
    EN: {
      ...EN,
      ...elementEN,
    },
    CN: {
      ...CN,
      ...elementZH,
    },
    FR: {
      ...FR,
      ...elementFR,
    },
  }, // 本地与iview国际结合
  silentTranslationWarn: process.NODE_ENV === "production", // true 去除console中黄色报错
});

Vue.use({
  i18n: (key, value) => i18n.t(key, value),
});

// 切换中英文调用该方法
export function setI18nLanguage(lang) {
  i18n.locale = lang;
  document.querySelector("html").setAttribute("lang", lang);
  return lang;
}
